package top.zy.lambda;

import lombok.extern.java.Log;
import top.zy.lambda.tool.VUtils;

import java.security.SecureRandom;

/**
 * 使用lambda制作一个方便的判断抛异常工具类
 *
 * @author ZackYoung
 * @version 1.0
 * @date 2021/12/26
 */
@Log
public class LambdaTests {
    public static void main(String[] args) {
        VUtils.isTrueOrFalse(true).trueOrFalseHandle(() -> log.info("true,我要开始秀了"), () -> log.info("false，秀不动了，run"));
        int age = new SecureRandom().nextInt(1, 200);
        VUtils.judge(age < 18, 18 <= age && age < 30, 30 <= age && age < 60, 60 <= age && age < 200).
                judge(() -> log.info("未成年"),
                        () -> log.info("年轻人"),
                        () -> log.info("中年人"),
                        () -> log.info("老年人"));

        VUtils.isBlankOrNoBlank("hello").presentOrElseHandle(System.out::println, () -> System.out.println("空字符串"));

        VUtils.getInstance.cd(true).handler(() -> System.out.println("ok"))
                .cd(true).handler(() -> System.out.println("ook"));

        VUtils.isTrue(true).throwMessage("参数正确，抛出异常");
    }
}
